package main

// OnePositiveTurn 顺时针旋转第一面 y=1
func (f *Info) OnePositiveTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Y != One {
			continue
		}
		v.X, v.Y, v.Z = f.FixPositiveTurn(One, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: PositiveTurn, Wall: One})
	f.output(f.record, false)
	f.check()
	return nil
}

// OneNegativeTurn 逆时针旋转第一面 y=1
func (f *Info) OneNegativeTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Y != One {
			continue
		}
		v.X, v.Y, v.Z = f.FixNegativeTurn(One, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: NegativeTurn, Wall: One})
	f.output(f.record, false)
	f.check()
	return nil
}

// TwoPositiveTurn 顺时针旋转第二面 x=3
func (f *Info) TwoPositiveTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.X != Three {
			continue
		}
		v.X, v.Y, v.Z = f.FixPositiveTurn(Two, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: PositiveTurn, Wall: Two})
	f.output(f.record, false)
	f.check()
	return nil
}

// TwoNegativeTurn 逆时针旋转第二面 x=3
func (f *Info) TwoNegativeTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.X != Three {
			continue
		}
		v.X, v.Y, v.Z = f.FixNegativeTurn(Two, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: NegativeTurn, Wall: Two})
	f.output(f.record, false)
	f.check()
	return nil
}

// ThreePositiveTurn 顺时针旋转第三面 z=1
func (f *Info) ThreePositiveTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Z != One {
			continue
		}
		v.X, v.Y, v.Z = f.FixPositiveTurn(Three, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: PositiveTurn, Wall: Three})
	f.output(f.record, false)
	f.check()
	return nil
}

// ThreeNegativeTurn 逆时针旋转第三面 z=1
func (f *Info) ThreeNegativeTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Z != One {
			continue
		}
		v.X, v.Y, v.Z = f.FixNegativeTurn(Three, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: NegativeTurn, Wall: Three})
	f.output(f.record, false)
	f.check()
	return nil
}

// FourPositiveTurn 顺时针旋转第四面 y=3
func (f *Info) FourPositiveTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Y != Three {
			continue
		}
		v.X, v.Y, v.Z = f.FixPositiveTurn(Four, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: PositiveTurn, Wall: Four})
	f.output(f.record, false)
	f.check()
	return nil
}

// FourNegativeTurn 逆时针旋转第四面 y=3
func (f *Info) FourNegativeTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Y != Three {
			continue
		}
		v.X, v.Y, v.Z = f.FixNegativeTurn(Four, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: NegativeTurn, Wall: Four})
	f.output(f.record, false)
	f.check()
	return nil
}

// FivePositiveTurn 顺时针旋转第五面 x=1
func (f *Info) FivePositiveTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.X != One {
			continue
		}
		v.X, v.Y, v.Z = f.FixPositiveTurn(Five, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: PositiveTurn, Wall: Five})
	f.output(f.record, false)
	f.check()
	return nil
}

// FiveNegativeTurn 逆时针旋转第五面 x=1
func (f *Info) FiveNegativeTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.X != One {
			continue
		}
		v.X, v.Y, v.Z = f.FixNegativeTurn(Five, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: NegativeTurn, Wall: Five})
	f.output(f.record, false)
	f.check()
	return nil
}

// SixPositiveTurn 顺时针旋转第六面 z=3
func (f *Info) SixPositiveTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Z != Three {
			continue
		}
		v.X, v.Y, v.Z = f.FixPositiveTurn(Six, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: PositiveTurn, Wall: Six})
	f.output(f.record, false)
	f.check()
	return nil
}

// SixNegativeTurn 逆时针旋转第六面 z=3
func (f *Info) SixNegativeTurn() error {
	select {
	case <-f.ctx.Done():
		return nil
	default:
		break
	}
	for k, v := range f.list {
		if v.Z != Three {
			continue
		}
		v.X, v.Y, v.Z = f.FixNegativeTurn(Six, v.X, v.Y, v.Z)
		f.list[k] = v
	}
	f.record = append(f.record, Record{Turn: NegativeTurn, Wall: Six})
	f.output(f.record, false)
	f.check()
	return nil
}
